package com.yh.homestay.security;

import com.yh.homestay.common.Md5Utils;
import org.apache.tomcat.util.security.MD5Encoder;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.MessageDigestPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;

/**
 * @ClassName MyPasswordEncoder
 * @Description 自定义加密
 * @Author GCL
 * @Date 2020/1/6 18:26
 */
@Component
public class MyPasswordEncoder implements PasswordEncoder {

    @Override
    public String encode(CharSequence staffName) {
        return Md5Utils.stringToMD5(staffName.toString());
    }

    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        return encodedPassword.equals(this.encode(rawPassword));
    }
}
